import Sequelize from 'sequelize'
import config from './config'

import electron from 'electron'
const { remote } = electron
const app = electron.app || remote.app
const configDir = app.getPath('userData')
const fileName = 'database.sqlite'
const SYS_PATH = `${configDir}/${fileName}`

const { sqlConfig } = config

const sequelizes = {}

const sqlCfgKeys = Object.keys(sqlConfig)

sqlCfgKeys.forEach(key => {
  // const configItem = sqlConfig[key]

  sequelizes[key] = new Sequelize({
    dialect: 'sqlite',
    storage: SYS_PATH,
    // define: {
    //   freezeTableName: true,
    //   underscored: true,
    //   timestamps: true,
    //   paranoid: true
    // },
    // benchmark: true,
    // timezone: '+08:00', // 东八区
    logging (sqlLog) {
      console.log(sqlLog)
    }
  })
})

export default sequelizes
